<html>
<body>
<?php
require_once("config.php");
require_once("utils.php");
echo $database_path ;

$directory_name=$upload_path;
$db=new SQLite3($dbfilename);

// get file list

$filelist=directoryToArray($directory_name,true);
foreach ($filelist as $filename) {
  if (!is_dir($filename)) {
   	$pfn=$filename;
    $v_filesize=filesize($pfn);
    $v_md5sum=md5_file($pfn);
    echo $pfn . "&nbsp;";
    $pfn=str_replace($_SERVER['DOCUMENT_ROOT'] . '/','/',$pfn);
    echo "<a href=\"" . $pfn . "\">" . basename($pfn) . "</a> <br/>";

// check duplicates
    $results=$db->query("SELECT COUNT(item_id) FROM item_t WHERE md5sum = '$v_md5sum'");
    $row=$results->fetchArray();
    if ($row[0]>0) {
     echo " already in database <br/> ";
    } else {
      $ok=$db->exec("INSERT INTO item_t (pfn, filesize, md5sum) VALUES ('$pfn', '$v_filesize', '$v_md5sum')");
      if (!$ok) die("cannot add to database: $error");
    }
  }
}


$db->close();
?>

<a href="index.html">back</a>

</body>
</html>
